<template>
  <w-modal ref="WModal" :title="model ? '修改首页链接' : '添加首页链接'" :success-func="successFunc" :span="[3]">
    <template v-slot:default>
      <a-form-item label="标题">
        <a-input
          v-decorator="['title', { rules: [{ required: true, message: '请输入' }], initialValue: model ? model.title : '' }]"
          placeholder="请填写标题..."
        />
      </a-form-item>
      <a-form-item label="跳转链接">
        <a-input
          v-decorator="['link', { rules: [{ required: true, message: '请输入' }], initialValue: model ? model.link : '' }]"
          placeholder="请填写跳转链接..."
        />
      </a-form-item>
    </template>
  </w-modal>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import WModal, { ModalFormComType } from '@/components/global/modal/form'
import { Admin } from '@/config/api'
import HomeLink from '@/models/homeLink'

@Component({
  name: 'ComAdminWebHomeLinkAdd',
  components: {
    WModal
  }
})
export default class ComAdminWebHomeLinkAdd extends Vue {
  model: HomeLink | null = null

  show (model?: HomeLink) {
    this.model = model || null;
    (this.$refs.WModal as ModalFormComType).show()
  }

  async successFunc (values: any) {
    const url = this.model ? `${Admin.homeLink.update}${this.model._id}` : Admin.homeLink.create
    const method = this.model ? '$put' : '$post'
    await this.$wAxios[method](url, values)
    this.$emit('reload')
  }
}
</script>

<style scoped></style>
